package danlib;

import java.util.*;

public class GeneticAlgorithm
{
	int generations;
	int steps;
	ArrayList<Genetic> list;
	
	public GeneticAlgorithm( int gen, int steps, ArrayList<Genetic> list )
	{
		generations = gen;
		this.steps = steps;
		this.list = list;
	}
	
	public void update()
	{
		for( int i = 0; i < list.size(); i++ )
		{
			Genetic gen = list.get(i);
			gen.complete();
		}
		int highScore = 0;
		int best = 0;
		for( int i = 0; i < list.size(); i++ )
		{
			int newScore = list.get(i).getScore();
			if( highScore < newScore )
			{
				highScore = newScore;
				best = i;
			}
		}
		Genetic bestOne = list.get(best);
		for( int i = 0; i < list.size(); i++ )
		{
			list.get(i).mutate( bestOne );
		}
	}
}